from app import create_app, UserModel
from flask import g, Flask, session

app = create_app()

@app.before_request
def my_before_request():
    user_id=session.get('user_id')
    if user_id:
        user=UserModel.query.get(user_id)
        setattr(g,"user",user)
    else:
        setattr(g,"user",None)

@app.context_processor
def my_context_processor():
    return {"user":g.user}

if __name__ == '__main__':
    app.run()